package com.limf.demo.java8;

import java.util.Optional;

public class OptionalTest {

	public static String getName(Person u) {
		return Optional.ofNullable(u)
				.map(user->user.firstName)
				.orElse("Unknown");
	}
	
	public static void main(String[] args) {
		Person p = new Person("li", "mf");
		System.out.println(getName(p));
	}
	
	/*public static String getChampionName(Competition comp) throws IllegalArgumentException {
		return Optional.ofNullable(comp)
				.map(c->c.getResult())
				.map(r->r.getChampion)
				.map(u->u.getName())
				.orElseThrow(()->new IllegalArgumentException("The value of param comp isn't available."));
	}*/
	
}
